<?php

use Illuminate\Http\Request;

Route::group([

    'middleware' => ['api'],
    'prefix' => '',

], function () {

    Route::post('/auth/bind-login', 'AuthController@bindLogin')->name('api.auth.bind-login');
    Route::get('/auth/bind-token', 'AuthController@bindToken')->name('api.auth.bind-token');

    Route::post('auth/login', 'AuthController@login')->name('api.auth.login');
    Route::post('auth/logout', 'AuthController@logout')->middleware('refresh.token')->name('api.auth.logout');
    Route::post('auth/refresh', 'AuthController@refresh')->name('api.auth.refresh');

    Route::post('auth/forgetpassword', 'AuthController@forgetPassword')->name('api.auth.forgetpassword');
    Route::post('auth/sendcode', 'AuthController@sendCode')->name('api.auth.sendcode');

    Route::any('/wechat', 'WeChatController@serve');
});

Route::group([
    'namespace' => 'Admin',
    'prefix' => '',
    'middleware' => [
        'refresh.token'
        , 'auth:api',
    ],
], function () {
    Route::get('dashboard', 'IndexController@index')->name('api.index.index');

    Route::post('checkupdate', 'IndexController@checkUpdate')->name('api.index.checkupdate');
    Route::post('donghuang/command', 'DhControlController@saveCommand')->name('api.dhcontrol.saveCommand');
    Route::get('unreadnum', 'RealwarnController@unreadNum')->name('api.realwarn.unreadNum');
});

Route::name('api.')
    ->prefix('')
    ->middleware(['refresh.token', 'auth:api', 'permission:api', 'scope'])
    ->group(function () {
        Route::get('auth/userinfo', 'AuthController@getUserInfo')->name('auth.getUserInfo');
        Route::put('auth/userinfo', 'AuthController@saveUserInfo')->name('auth.saveUserInfo');
        Route::put('auth/password', 'AuthController@modifyPassword')->name('auth.modifyPassword');

        Route::get('auth/authcode', 'AuthController@authcode')->name('auth.authcode');
        Route::put('auth/authcode', 'AuthController@authcode')->name('auth.authcode');
    });

Route::name('api.')
    ->namespace('Weixin')
    ->prefix('')
    ->middleware(['refresh.token', 'auth:api', 'scope', 'scope'])
    ->group(function () {
        Route::resource('wxusers', 'WxUserController');
        Route::resource('wxmenu', 'WxMenuController');
        Route::post('wxmenu/menu', 'WxMenuController@updateMenu')->name('wxmenu.updateMenu');
        Route::resource('wxtemplate', 'TemplateMessageController');
    });

Route::name('api.')
    ->namespace('Admin')
    ->prefix('')
    ->middleware(['refresh.token', 'auth:api', 'permission:api', 'scope'])
    ->group(function () {
        Route::resource('users', 'UserController');
        Route::get('user/roles/{user}', 'UserController@getRoles')->name('users.getRoles');
        Route::put('user/roles', 'UserController@updateRoles')->name('users.updateRoles');
        Route::resource('roles', 'RoleController');
        Route::get('roles/{role}/ability', 'RoleController@getRoleAbilities')->name('roles.ability');
        Route::put('roles/{role}/ability', 'RoleController@saveRoleAbility')->name('roles.ability');
        Route::resource('permission', 'PermissionController');
        Route::get('permission/{name}/search', 'PermissionController@search')->name('permission.search');
        // Route::resource('menu', 'MenuController');
        // Route::post('menu/{menu}/buttons', 'MenuController@createButton')->name('menu.createButton');

        // Route::get('menu/tree/all', 'MenuController@tree')->name('menu.tree');

        Route::resource('newmenu', 'NewMenuController');

        Route::resource('company', 'CompanyController');
        Route::get('company/{company}/search', 'CompanyController@search')->name('company.search');
        Route::post('upload', 'UploadController@store')->name('upload.store');
        Route::delete('upload', 'UploadController@destroy')->name('upload.destroy');

        Route::resource('devicetype', 'DevicetypeController');
        Route::resource('deviceinfo', 'DeviceinfoController');

        Route::apiResource('subtype', 'SubtypeController');

        Route::get('deviceinfo/devicetype/all', 'DeviceinfoController@getDeviceType')->name('deviceinfo.devicetype');
        Route::get('deviceinfo/{company}/area', 'DeviceinfoController@getCompanyArea')->name('deviceinfo.area');

        Route::get('deviceinfo/protocol/{tid}', 'DeviceinfoController@getDeviceProtocol')->name('deviceinfo.getDeviceProtocol');

        // Route::resource('area', 'AreaController');
        Route::resource('newarea', 'NewAreaController');
        Route::get('newarea/device/{areaid}', 'NewAreaController@device')->name('newarea.device');

        Route::get('data', 'DataController@index')->name('data.index');
        Route::get('history', 'DataController@data')->name('data.history');
        Route::get('data/real', 'DataController@real')->name('data.real');
        Route::get('data/area', 'DataController@area')->name('data.area');
        Route::get('data/company', 'DataController@company')->name('data.company');
        Route::get('data/type/device', 'DataController@devicesByType')->name('data.devicesByType');

        Route::get('data/fields/{typeid}', 'DataController@getFields')->name('data.fields');

        Route::get('alarm/index', 'AlarmController@index')->name('alarm.index');
        Route::get('statistic/index', 'StatisticController@index')->name('statistic.index');

        // Route::get('monitor/index', 'MonitorController@index')->name('monitor.index');
        // Route::post('monitor/data', 'MonitorController@deviceData')->name('monitor.data');
        // Route::post('monitor/realdata', 'MonitorController@deviceRealData')->name('monitor.realdata');
        // Route::post('monitor/areadevice', 'MonitorController@getDevicesByArea')->name('monitor.areadevice');

        Route::get('userlog', 'UserLogController@index')->name('userlog.index');
        Route::post('control/{pdi}/update', 'ControlController@update')->name('control.update');
        Route::get('control/device', 'ControlController@device')->name('control.device');
        Route::get('control/devicedata', 'ControlController@deviceData')->name('control.devicedata');
        Route::post('control/command', 'ControlController@saveCommand')->name('control.savecommand');

        Route::post('control/switch', 'ControlController@saveInputData')->name('control.saveinputdata');
        Route::post('control/out', 'ControlController@saveOutputData')->name('control.saveoutputdata');
        Route::post('control/index', 'ControlController@index')->name('control.index');

        Route::resource('warndefine', 'WarndefineController');

        Route::get('realwarn', 'RealwarnController@index')->name('realwarn.index');
        Route::post('realwarn/confirm', 'RealwarnController@addWarnLog')->name('realwarn.addWarnLog');

        Route::resource('warnnotify', 'WarnnotifyController');
        Route::resource('warnuser', 'WarnuserController');
        Route::post('warnuser/{warnuser}/warnsetting', 'WarnuserController@warnSetting')->name('warnuser.warnsetting');

        Route::get('report', 'ReportController@index')->name('report.index');
        Route::get('report/historysum', 'ReportController@historysum')->name('report.historysum');
        Route::get('report/assetsum', 'ReportController@assetsum')->name('report.assetsum');
        Route::get('report/day', 'ReportController@water')->name('report.day');
        Route::get('report/month/{month}', 'ReportController@monthWater')->name('report.month');

        Route::get('donghuang/index', 'DonghuangController@index')->name('donghuang.index');
        Route::post('donghuang/device', 'DonghuangController@device')->name('donghuang.device');
        Route::post('donghuang/realdata', 'DonghuangController@realData')->name('donghuang.realdata');
        Route::post('donghuang/storedevice', 'DonghuangController@storeDevice')->name('donghuang.storeDevice');
        Route::put('donghuang/{id}/update', 'DonghuangController@update')->name('donghuang.update');
        Route::delete('donghuang/{id}', 'DonghuangController@destroy')->name('donghuang.destroy');

        Route::get('system/index', 'SystemController@index')->name('system.index');
        Route::post('system/email', 'SystemController@storeEmail')->name('system.storeEmail');
        Route::post('system/sms', 'SystemController@storeSms')->name('system.storeSms');
        Route::post('system/3d', 'SystemController@store3d')->name('system.store3d');
        Route::post('system/voice', 'SystemController@storeVoice')->name('system.storeVoice');
        Route::post('system/upgrade', 'SystemController@storeUpgrade')->name('system.storeUpgrade');
        Route::post('system/cache', 'SystemController@updateCache')->name('system.updateCache');

        Route::post('system/testsend', 'SystemController@testsend')->name('system.testsend');
        Route::post('system/testsendsms', 'SystemController@testsendsms')->name('system.testsendsms');

        Route::resource('apk', 'ApkController');

        Route::get('backup/index', 'BackupController@index')->name('backup.index');
        Route::delete('backup/{filename}', 'BackupController@destroy')->name('backup.destroy');
        Route::post('backup/run', 'BackupController@dataBackup')->name('backup.dataBackup');
        Route::post('backup/{filename}', 'BackupController@download')->name('backup.download');

        //公告管理
        Route::resource('announcement', 'AnnouncementController');

        //报表管理
        Route::get('report-setting/params', 'ReportSettingController@params')->name('report-setting.params');
        Route::post('report-setting/update-table/{id}', 'ReportSettingController@updateTable')->name('report-setting.updateTable');
        Route::post('report-setting/update-report/{table}', 'ReportSettingController@report')->name('report-setting.report');
        Route::apiResource('report-setting', 'ReportSettingController');
        Route::apiResource('report-setting-field', 'ReportSettingFieldController');


        //设备参数
        Route::get('device-params', 'DeviceParamsController@index')->name('device-params.index');
        Route::post('device-params', 'DeviceParamsController@update')->name('device-params.update');

        //上下限阀值
        Route::get('limit/index', 'LimitController@index')->name('limit.index');
        Route::post('limit/command', 'LimitController@saveCommand')->name('limit.command');
    });
